import { Schema, model } from 'mongoose';

export interface IProject {
  _id?: string;
  apps: any[];
  createdAt?: Date;
  name: string; // 项目名称
  remark: string; // 项目描述
  updatedAt?: Date;
}

const ProjectSchema = new Schema<IProject>(
  {
    apps: {
      default: [],
      ref: 'App',
      type: [
        new Schema(
          {
            app: {
              required: true,
              type: Schema.Types.ObjectId,
            },
            // 参数值
            value: {
              required: true,
              type: String,
            },
          },
          // 不为子文档生成_id
          { _id: false },
        ),
      ],
    },
    // 项目名称
    name: {
      required: true,
      trim: true,
      type: String,
    },
    // 项目描述
    remark: {
      default: '',
      trim: true,
      type: String,
    },
  },
  {
    // 自动添加createdAt和updatedAt时间戳
    timestamps: true,
  },
);

export const ProjectModel = model<IProject>('Project', ProjectSchema);
